<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\ResourceCollection;

class SeaCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'status' => 1,
            'message'=>'请求数据成功',
            'data' => $this->collection->map(function($item){
                $nextTime=$item->next_time;
                if ($nextTime==null||Carbon::parse($nextTime)->addDays(-3)->gt(Carbon::now())){
                    $canFollow=1;
                }else{
                    $canFollow=0;
                }

                return [
                  'customer_id'=>$item->customer_id,
                  'mobile'=>  substr_replace($item->mobile,'****',3,4),
                  'industry'=>$item->industry,
                    'industry_id'=>$item->industry_id,
                    'name'=>$item->name,
                    'can_follow'=>$canFollow,
                    'created_at'=>Carbon::parse($item->created_at)->toDateTimeString(),
                    'area'=>$item->area
                ];
                return $value;
            })
        ];
    }
}
